clc
clear

% system no 1
r = 2;
L = 4;
M = 4;
x = [0 1];

disp('** System no 1 (sign-magnitude)');
fprintf('r=%d, L=%d, M=%d, x={%s}\n\n',r,L,M,mat2str(x));

disp('* ulp');
fprintf('r^-L = %d^-%d = %.32f\n',r,L, r^-L);
disp(' ');

disp('* Most positive representable number');
mpn = r^(M-1)-r^-L;
fprintf('r^(M-1)-ulp = %d^(%d-1)-%d^-%d=%.32f\n',r,M,r,L,mpn);
disp(' ');

disp('* Most negative representable number');
mnn = -(r^(M-1)-r^-L);
fprintf('-(r^(M-1)-ulp) = -(%d^(%d-1)-%d^-%d)=%.32f\n',r,M,r,L,mnn);
disp(' ');

% system no 2
r = 2;
L = 4;
M = 4;
x = [0 1];

disp('** System no 2 (ones complement)');
fprintf('r=%d, L=%d, M=%d, x={%s}\n\n',r,L,M,mat2str(x));

disp('* ulp');
fprintf('r^-L = %d^-%d = %.32f\n',r,L, r^-L);
disp(' ');

disp('* Most positive representable number');
mpn = r^(M-1)-r^-L;
fprintf('r^(M-1)-ulp = %d^(%d-1)-%d^-%d=%.32f\n',r,M,r,L,mpn);
disp(' ');

disp('* Most negative representable number');
mnn = -(r^(M-1)-r^-L);
fprintf('-(r^(M-1)-ulp) = -(%d^(%d-1)-%d^-%d)=%.32f\n',r,M,r,L,mnn);
disp(' ');

% system no 3
r = 2;
L = 4;
M = 4;
x = [0 1];

disp('** System no 3 (twos complement)');
fprintf('r=%d, L=%d, M=%d, x={%s}\n\n',r,L,M,mat2str(x));

disp('* ulp');
fprintf('r^-L = %d^-%d = %.32f\n',r,L, r^-L);
disp(' ');

disp('* Most positive representable number');
mpn = r^(M-1);
fprintf('r^(M-1)=%d^(%d-1)=%.32f\n',r,M,mpn);
disp(' ');

disp('* Most negative representable number');
mnn = -(r^(M-1)-r^-L);
fprintf('-(r^(M-1)-ulp) = -(%d^(%d-1)-%d^-%d)=%.32f\n',r,M,r,L,mnn);
disp(' ');


% system no 4
r = 5;
L = 4;
M = 4;
x = [0 1 2 3 4];

disp('** System no 4 (sign-magnitude)');
fprintf('r=%d, L=%d, M=%d, x={%s}\n\n',r,L,M,mat2str(x));

disp('* ulp');
fprintf('r^-L = %d^-%d = %.32f\n',r,L, r^-L);
disp(' ');

disp('* Most positive representable number');
mpn = r^(M-1)-r^-L;
fprintf('r^(M-1)-ulp = %d^(%d-1)-%d^-%d=%.32f\n',r,M,r,L,mpn);
disp(' ');

disp('* Most negative representable number');
mnn = -(r^(M-1)-r^-L);
fprintf('-(r^(M-1)-ulp) = -(%d^(%d-1)-%d^-%d)=%.32f\n',r,M,r,L,mnn);
disp(' ');

% system no 5
r = 5;
L = 4;
M = 4;
x = [0 1 2 3 4];

disp('** System no 5 (ones complement)');
fprintf('r=%d, L=%d, M=%d, x={%s}\n\n',r,L,M,mat2str(x));

disp('* ulp');
fprintf('r^-L = %d^-%d = %.32f\n',r,L, r^-L);
disp(' ');

disp('* Most positive representable number');
mpn = r^(M-1)-r^-L;
fprintf('r^(M-1)-ulp = %d^(%d-1)-%d^-%d=%.32f\n',r,M,r,L,mpn);
disp(' ');

disp('* Most negative representable number');
mnn = -(r^(M-1)-r^-L);
fprintf('-(r^(M-1)-ulp) = -(%d^(%d-1)-%d^-%d)=%.32f\n',r,M,r,L,mnn);
disp(' ');

% system no 6
r = 5;
L = 4;
M = 4;
x = [0 1 2 3 4];

disp('** System no 6 (twos complement)');
fprintf('r=%d, L=%d, M=%d, x={%s}\n\n',r,L,M,mat2str(x));

disp('* ulp');
fprintf('r^-L = %d^-%d = %.32f\n',r,L, r^-L);
disp(' ');

disp('* Most positive representable number');
mpn = r^(M-1);
fprintf('r^(M-1)=%d^(%d-1)=%.32f\n',r,M,mpn);
disp(' ');

disp('* Most negative representable number');
mnn = -(r^(M-1)-r^-L);
fprintf('-(r^(M-1)-ulp) = -(%d^(%d-1)-%d^-%d)=%.32f\n',r,M,r,L,mnn);
disp(' ');

%function [] = part2()
%end

